<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body onload="verifyToken()">
<div class="layuimini-container">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="load">下载</a>
        </script>

    </div>
</div>
<script src="../js/lay-module/http/http.js"></script>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;


        table.render({
            elem: '#currentTableId',
            url: $api + '/risk/tb-file-staffstation/list',
            toolbar: '#toolbarDemo',
            headers:{
                Authorization: layui.data('table')['Authorization']
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                {type: "numbers" , width: 50},
                {field: 'userId', title: 'ID', hide: true},
                {field: 'fileId', width: 100, title: '文件id', hide: true},
                {field: 'fileName', width: 150, title: '文件名'},
                {field: 'file', width:150, title: '文件路径'},
                {field: 'state', title: '业务', minWidth: 50, templet: function(res){
                        return getRiskFileStaffStation(res.state)
                    }
                },
                {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [1, 10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(JSON.stringify(data))
            if (obj.event === 'load') {

                $.ajax({
                    type: 'POST',
                    url: $api + 'risk/tb-file-staffstation/updateState?fileId=' + data.fileId,
                    contentType: "application/json;charset=utf-8",
                    async: false,
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    success: function (res) {
                        // 对下拉列表进行拼接

                        layer.msg(res.message)
                        console.log(data.fileId)
                        window.location.href=data.file

                    }
                });

            }
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    userId: data.field.userId,
                    fileId: data.field.fileId,
                    fileName: data.field.fileName,
                    file: data.field.file,
                    state: data.field.state,
                },
            }, 'data');
        });


    });
</script>

</body>
</html>